import Vuex from 'vuex'
import Vue from 'vue'
const countAbout={
    namespaced: true,
    actions:{
        jia:function(context,value){
            context.commit('JIA',value)
        },
        jian:function(context,value){
    context.commit('JIAN',value)
        },
    jiaOdd:function(context,value){
        if(context.state.sum%2!==0){
    context.commit('JIA_ODD',value)
    }
    },
    jiaWait:function(context,value){
        setTimeout(()=>{
            context.commit('JIA_WAIT',value)
        },1000)
    }
    },
    mutations:{
        JIA(state,value){
            state.sum+=value
        },
        JIAN(state,value){
            state.sum-=value
        },
        JIA_ODD(state,value){
                state.sum+=value
        },
        JIA_WAIT(state,value){
                state.sum+=value
        },
    },
    state:{
        sum:0,
        where:'北京',
        what:'调酒',
    },
    getters:{
        bigSum:function(state){
            return state.sum*10
        }
    }
}
const personAbout={
    namespaced: true,
    actions:{
        addPersonWang(context,person){
            if(person.name.indexOf('王')===0){
                context.commit('ADDPERSON',person)
            }else{
                alert('名字必须以王开头')
            }
        }
    },
    mutations:{
        ADDPERSON(state,person){
            state.PersonList.push(person)
        }
    },
    state:{
        PersonList:[{name:'张三',id:'01'}]
    },
    getters:{
        firstPersonName(state){
            return state.PersonList[0].name
        }
    }
}
Vue.use(Vuex)
export default new Vuex.Store({
    modules:{
        countAbout,
        personAbout
    }
})